<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java 重载与重写：深入理解面向对象编程的核心概念</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 2px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border-color: #667eea;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 12px;
            overflow: hidden;
            position: relative;
        }
        
        .code-header {
            background: #2d2d2d;
            padding: 10px 20px;
            font-size: 14px;
            color: #888;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 8px;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 16px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 24px;
            margin-bottom: 20px;
        }
        
        .section-divider {
            width: 80px;
            height: 4px;
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
            margin: 40px auto;
            border-radius: 2px;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 20px 30px;
            border-radius: 16px;
            margin: 30px 0;
            position: relative;
            overflow: hidden;
        }
        
        .highlight-box::before {
            content: '';
            position: absolute;
            top: -50%;
            right: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
            animation: pulse 3s ease-in-out infinite;
        }
        
        @keyframes pulse {
            0%, 100% { transform: scale(0.8); opacity: 0.5; }
            50% { transform: scale(1.2); opacity: 0.8; }
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 40px 0;
        }
        
        pre code {
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            font-size: 14px;
            line-height: 1.6;
        }
        
        .keyword { color: #569cd6; }
        .string { color: #ce9178; }
        .comment { color: #6a9955; }
        .method { color: #dcdcaa; }
        .class-name { color: #4ec9b0; }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white">
        <div class="container mx-auto px-6 py-20">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 leading-tight">
                    Java 重载与重写
                </h1>
                <p class="text-xl md:text-2xl opacity-90 mb-8">
                    深入理解面向对象编程的核心概念
                </p>
                <div class="flex justify-center gap-4 text-sm">
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full">
                        <i class="fas fa-code mr-2"></i>面向对象编程
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full">
                        <i class="fas fa-layer-group mr-2"></i>多态性
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full">
                        <i class="fas fa-graduation-cap mr-2"></i>核心概念
                    </span>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12 max-w-6xl">
        <!-- Introduction -->
        <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12 mb-12">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">重</span>载（Overloading）和重写（Overriding）是 Java 中常见的两个概念，它们虽然名称相似，但在使用和实现上有显著的区别。理解这两个概念对于掌握 Java 的多态性和面向对象编程至关重要。
            </p>
        </div>

        <!-- Concept Visualization -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold text-center mb-8 text-gray-800">概念关系图</h2>
            <div class="mermaid">
                graph TD
                    A[Java 方法机制] --> B[重载 Overloading]
                    A --> C[重写 Overriding]
                    B --> D[同一类中]
                    B --> E[方法名相同]
                    B --> F[参数列表不同]
                    C --> G[继承关系中]
                    C --> H[方法签名相同]
                    C --> I[实现多态]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                    style B fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
                    style C fill:#f5576c,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>

        <!-- Overloading Section -->
        <div class="grid md:grid-cols-2 gap-8 mb-12">
            <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <div class="feature-icon">
                    <i class="fas fa-copy"></i>
                </div>
                <h2 class="text-3xl font-bold mb-6 text-gray-800">重载（Overloading）</h2>
                <p class="text-gray-600 mb-6 leading-relaxed">
                    重载是在同一个类中定义多个方法，它们具有相同的名称，但参数列表（参数的类型、数量或顺序）不同。
                </p>
                
                <h3 class="text-xl font-semibold mb-4 text-gray-700">
                    <i class="fas fa-star text-yellow-500 mr-2"></i>核心特点
                </h3>
                <ul class="space-y-3 text-gray-600">
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                        <div>
                            <strong>方法名称相同：</strong>重载的方法必须有相同的名称
                        </div>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                        <div>
                            <strong>参数列表不同：</strong>可以是参数类型、个数或顺序的不同
                        </div>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                        <div>
                            <strong>返回值类型可以不同：</strong>但不能作为重载的唯一条件
                        </div>
                    </li>
                </ul>
            </div>

            <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <div class="feature-icon">
                    <i class="fas fa-sync-alt"></i>
                </div>
                <h2 class="text-3xl font-bold mb-6 text-gray-800">重写（Overriding）</h2>
                <p class="text-gray-600 mb-6 leading-relaxed">
                    重写是在子类中对父类中已存在的方法进行重新定义，方法名、参数列表必须与父类中被重写的方法完全相同。
                </p>
                
                <h3 class="text-xl font-semibold mb-4 text-gray-700">
                    <i class="fas fa-star text-yellow-500 mr-2"></i>核心特点
                </h3>
                <ul class="space-y-3 text-gray-600">
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                        <div>
                            <strong>方法签名相同：</strong>方法名和参数列表必须完全一致
                        </div>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                        <div>
                            <strong>返回值兼容：</strong>相同或是其子类型（协变返回类型）
                        </div>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                        <div>
                            <strong>访问权限：</strong>不能比父类方法更严格
                        </div>
                    </li>
                </ul>
            </div>
        </div>

        <!-- Code Examples -->
        <div class="bg-white rounded-2xl shadow-xl overflow-hidden mb-12">
            <div class="p-8">
                <h2 class="text-3xl font-bold mb-8 text-gray-800 text-center">代码示例</h2>
                
                <!-- Overloading Example -->
                <div class="mb-8">
                    <h3 class="text-2xl font-semibold mb-4 text-gray-700">
                        <i class="fas fa-code text-purple-500 mr-2"></i>重载示例
                    </h3>
                    <div class="code-block">
                        <div class="code-header">
                            <i class="fas fa-file-code"></i>
                            <span>OverloadingDemo.java</span>
                        </div>
                        <pre class="p-6"><code><span class="keyword">public class</span> <span class="class-name">OverloadingDemo</span> {
    <span class="comment">// 重载方法1：两个整数相加</span>
    <span class="keyword">public int</span> <span class="method">add</span>(<span class="keyword">int</span> a, <span class="keyword">int</span> b) {
        <span class="keyword">return</span> a + b;
    }

    <span class="comment">// 重载方法2：三个整数相加</span>
    <span class="keyword">public int</span> <span class="method">add</span>(<span class="keyword">int</span> a, <span class="keyword">int</span> b, <span class="keyword">int</span> c) {
        <span class="keyword">return</span> a + b + c;
    }

    <span class="comment">// 重载方法3：两个浮点数相加</span>
    <span class="keyword">public double</span> <span class="method">add</span>(<span class="keyword">double</span> a, <span class="keyword">double</span> b) {
        <span class="keyword">return</span> a + b;
    }
}</code></pre>
                    </div>
                </div>

                <!-- Overriding Example -->
                <div>
                    <h3 class="text-2xl font-semibold mb-4 text-gray-700">
                        <i class="fas fa-code text-purple-500 mr-2"></i>重写示例
                    </h3>
                    <div class="code-block">
                        <div class="code-header">
                            <i class="fas fa-file-code"></i>
                            <span>OverridingDemo.java</span>
                        </div>
                        <pre class="p-6"><code><span class="keyword">class</span> <span class="class-name">Parent</span> {
    <span class="keyword">public void</span> <span class="method">display</span>() {
        System.out.println(<span class="string">"父类的 display 方法"</span>);
    }
}

<span class="keyword">class</span> <span class="class-name">Child</span> <span class="keyword">extends</span> <span class="class-name">Parent